package com.ttt.gdfood.mapper;

import com.ttt.gdfood.entity.Collection;
import com.ttt.gdfood.entity.Contact;
import org.apache.ibatis.annotations.*;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Mapper
public interface CollectionMapper {
    // 获取用户收藏的笔记
    @Select("SELECT * FROM collection WHERE uid=#{uid}")
    @Results({
            @Result(property = "notes", column = "cn_id", many = @Many(select = "com.ttt.gdfood.mapper.NoteMapper.noteByNoteId")),
            @Result(property = "cn_id",column = "cn_id")
    })
    @Transactional
    List<Collection> getCollection(int uid);

    // 获取笔记被收藏的用户id
    @Select("SELECT uid FROM collection WHERE cn_id=#{cn_id}")
    @Transactional
    List<Collection> getUid(int cn_id);

    // 用户收藏笔记
    @Insert("INSERT into collection (`uid`, `cn_id`) VALUES (#{uid},#{cn_id})")
    @Transactional
    void insertCollection(int uid,int cn_id);

    // 根据用户收藏的笔记id删除
    @Delete("DELETE FROM collection WHERE cn_id=#{cn_id}")
    void delCollectionByCnid(int cn_id);
}
